<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" import="java.sql.*"%>
<%@ page import="ookweb.Conn"%>
<%@ page import="ookweb.Data"%>
<%@ include file="../public.jsp" %> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/ookweb/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">    
    <title>顶部菜单</title>    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<link rel="stylesheet" type="text/css" href="<%=basePath%>/images/m/css.css">
	<script type="text/javascript"> 
        var GB_ROOT_DIR = "<%=basePath%>images/m/greybox/";
	</script>
	<script type="text/javascript" src="<%=basePath%>images/m/greybox/AJS.js"></script>
	<script type="text/javascript" src="<%=basePath%>images/m/greybox/AJS_fx.js"></script>
	<script type="text/javascript" src="<%=basePath%>images/m/greybox/gb_scripts.js"></script>
	<link href="<%=basePath%>images/m/greybox/gb_styles.css" rel="stylesheet" type="text/css" media="all" />
	<script src="<%=basePath%>js/jquery-1.5.1.min.js"  type="text/javascript" ></script>
	<script src="<%=basePath%>js/public.js"  type="text/javascript" ></script>
  </head>
  
  <body>
   <br/>
  <%
      Data data=new Data(dbuser,dbpass,dburl);
     Conn con=new Conn(dbuser,dbpass,dburl);
    String lid=(String)request.getParameter("lid");
    String act=(String)request.getParameter("act");
    int intT=0;
    
     if("d".equals(act) && !("".equals(lid)) && lid!=null){
       data.delete("delete from web_leftmenu where leftid="+lid);  
       act="";    
     }
    
    
    if(!("".equals(act) ||  act==null)){
       String leftname="",sort="",menuid="",spath="";
      if("save".equals(act)){
         String sql="";
         menuid=(String)request.getParameter("menuid");
         leftname=(String)request.getParameter("leftname");
         sort=(String)request.getParameter("sort");
         spath=(String)request.getParameter("spath");
      
         int num=0;
         if(!("".equals(lid)) && lid!=null){
         sql="update web_leftmenu set leftname='"+leftname+"',sort="+sort+",menuid="+menuid+",path='"+spath+"'  where leftid="+lid;
         num=data.update(sql);
         if(num>0){out.print("<script>alert(\"已成功修改\");</script>");}
         }else{
         java.text.SimpleDateFormat formatter=new java.text.SimpleDateFormat("yyyy-MM-dd");
         java.util.Date currentTime=new java.util.Date();
         String time=formatter.format(currentTime);
         sql="insert into web_leftmenu(leftid,menuid,leftname,sort,path,addtime)values(WEB_TOPMENU_SEQ.nextval,"+menuid+",'"+leftname+"',"+sort+",'"+spath+"',to_date('"+time+"','yyyy/mm/dd'))";
         num=data.insert(sql);
         if(num>0){out.print("<script>alert(\"已成功添加\");</script>");}
         }
         
      }else if("e".equals(act) && !("".equals(lid)) && lid!=null){
			 ResultSet rs=con.getRs("SELECT * FROM web_leftmenu where leftid="+lid);
			 if(rs.next()){
			 leftname=rs.getString("leftname");sort=rs.getString("sort");
			 menuid=rs.getString("menuid");spath=rs.getString("path");
			 }
      }else{lid="";}
      %>
      <form action="<%=basePath%>webadmin/system/leftmenu.jsp?act=save&lid=<%=lid%>" method="post" id="frm">
	  <table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="92acbb">
	   <tr>
	    <td align="center" width="140">左边菜单</td>
	    <td align="left">
<select name="menuid" id="menuid">
<option value="" >请选择</option>
<% 
ResultSet rss=con.getRs("select * from web_topmenu");
while(rss.next()){
 %>
  <option value="<%=rss.getString("menuid") %>" <%if(menuid.equals(rss.getString("menuid"))){out.print("selected");} %>><%=rss.getString("menuname") %></option>
<%} %>
</select></td>
	  </tr>
	  <tr>
	    <td align="center" width="140">菜单名</td>
	    <td align="left"> <input name="leftname" id="leftname" type="text" class="inp" value="<%=leftname %>"/></td>
	  </tr>
	  <tr>
	    <td align="center" width="140">排序</td>
	    <td align="left"> <input name="sort" id="sort" type="text" class="inp" chksort="^[0-9]{4,16}$" value="<%=sort %>"/> 注:数字编号</td>
	  </tr>
	   <tr>
	    <td align="center" width="140">路径</td>
	    <td align="left"> <input name="spath" id="spath" type="text" class="inp" value="<%=spath %>"/></td>
	  </tr>
	   <tr>
	    <td align="center" width="140">操作</td>
	    <td align="left"> <input name="cmd" id="savecmd" type="button" class="inp" value="保存" style="width:60px;"/></td>
	  </tr>
	 </table>
	 </form>
   <script type="text/javascript">
	$(document).ready(function() {
		$('#savecmd').click(function() {
		  if($('#menuid').attr('value')==''){
		  alert('请选择顶部菜单');return;
		  }else if($('#leftname').attr('value')==''){
		  alert('请输入菜单名称');return;
		  }else if(objchkstr($('#sort'),'chksort')){
		  alert('请输入排序值,注意是数字');
		  return;
		  }else if($('#spath').attr('value')==''){
		  alert('请输入排序值,注意是数字');
		  return;
		  }else{
		    $("#frm").submit();
		  }
		});
	});
   </script>
   <% }else{%>
  【<span class="bt">左部菜单管理</span>】
 《<a href="<%=basePath%>webadmin/system/leftmenu.jsp?act=a" title="增加新菜单" rel="gb_page_center[600,200]">添加新菜单</a>》
 <table width="100%" border="0" cellpadding="1" cellspacing="1" bgcolor="92acbb">
  <tr>
    <th  align="left">菜单名</th>
    <th width="80">排序</th>
    <th width="140">时间</th>
    <th width="140">操作</th>
  </tr>
  <% 
//变量声明 
String mysql=new String(); //SQL语句
mysql=" web_leftmenu where 1=1";
int intRowCount=0;  //总的记录数
int intPageCount=0; //总的页数
int intPageSize=15; //每页显示的记录数
int intPage; //待显示页码 
String strPage=new String(); //用来接收当页码参数
int begin_no=0; //开始的rownum记录号
int end_no=0;  //结束的rownum记录号

//取得待显示页码 
strPage = request.getParameter("page"); 
if(strPage==null){//表明在QueryString中没有page这一个参数，此时显示第一页数据 
intPage = 1; 
} 
else{//将字符串转换成整型 
intPage = java.lang.Integer.parseInt(strPage); 
if(intPage<1) intPage = 1; 
} 
//得到总的数据记录行数
intRowCount=data.getRowCount(mysql); //总记录数
//计算总共要分多少页
intPageCount = (intRowCount+intPageSize-1) / intPageSize; 
//调整待显示的页码 
if(intPage>intPageCount) intPage = intPageCount; 
	    begin_no=(intPage-1) * intPageSize + 1; 
        end_no = intPage * intPageSize;
	    mysql="select a.leftid,a.leftname,a.sort,a.menuid,a.path,a.addtime,b.menuname from (select rownum row_id,leftid,leftname,sort,menuid,path,addtime from (SELECT leftid,leftname,sort,menuid,path,addtime FROM web_leftmenu order by menuid desc,leftid asc))";
	    mysql=mysql+" a left join web_topmenu b on a.menuid=b.menuid where row_id between " +begin_no+ " and " +end_no;
	    ResultSet rs=con.getRs(mysql);
		int i=0;
		String menuname="";
		while(rs.next()){
		i++;menuname=rs.getString("menuname")+"->"+rs.getString("leftname");
	 %>
	<tr onmouseover='$(this).css({"background":"#cee1ed"});' onmouseout='$(this).css({"background":"#fff"});'>
    <td  align="left"><%=menuname%></td>
    <td width="80" align="center"><%=rs.getString("sort") %></td>
    <td width="140" align="center"><%=rs.getDate("addtime") %></td>
    <td width="140" align="center"><span class="area"><a title="<%=menuname %>_修改" rel="gb_page_center[600,200]" href="<%=basePath%>webadmin/system/leftmenu.jsp?act=e&lid=<%=rs.getString(1) %>"> 编辑 </a></span> <span class="area"><a href="javascript:confirmDelete('<%=basePath%>webadmin/system/leftmenu.jsp?act=d&lid=<%=rs.getString(1) %>&page=<%=intPage %>');"> 删除 </a></span></td>
    </tr>
   <%}
   if(intPageCount>1){
   %>
   <tr>
    <td colspan="5" align="center">
     第<%=intPage%>页 共<%=intPageCount%>页 
<a href="<%=basePath%>webadmin/system/leftmenu.jsp?page=1">首页</a>
<%if(intPage>1){%><a href="<%=basePath%>webadmin/system/leftmenu.jsp?page=<%=intPage-1%>">上一页</a><%}%> 
<%if(intPage<intPageCount){%><a href="<%=basePath%>webadmin/system/leftmenu.jsp?page=<%=intPage+1%>">下一页</a><%}%> 
<a href="<%=basePath%>webadmin/system/leftmenu.jsp?page=<%=intPageCount%>">尾页</a>
   </td>
   </tr>
   <%} %>
 </table>
 <% }  con.close();%>
  </body>
</html>
